package com.yang.rocket;

import com.yang.domain.OperationLog;
import com.yang.service.OperationLogService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
//topic要与订阅的topic一致
//使用集群模式
@RocketMQMessageListener(topic = "user-topic", consumerGroup = "user-logging-consumer", messageModel = MessageModel.CLUSTERING)
public class RocketMQConsumer implements RocketMQListener<OperationLog> {
    @Autowired
    private OperationLogService operationLogService;

    @Override
    public void onMessage(OperationLog operationLog) {
        operationLogService.insertOperationLog(operationLog);
    }
}
